<?php

declare(strict_types=1);

namespace Tempest\Http;

enum Method: string
{
    case GET = 'GET';
    case HEAD = 'HEAD';
    case POST = 'POST';
    case PUT = 'PUT';
    case DELETE = 'DELETE';
    case CONNECT = 'CONNECT';
    case OPTIONS = 'OPTIONS';
    case TRACE = 'TRACE';
    case PATCH = 'PATCH';

    public static function trySpoofingFrom(string $method): ?Method
    {
        $method = Method::tryFrom(strtoupper($method));

        return match ($method) {
            self::DELETE, self::PATCH, self::PUT => $method,
            default => null,
        };
    }
}
